<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <th:block th:include="include :: header('修改')"/>
</head>
<body>
<form class="layui-form" action="">
    <div class="mainBox">
        <div class="main-container">
            <div class="main-container">

                <div class="layui-form-item layui-hide">
                    <label class="layui-form-label">编号</label>
                    <div class="layui-input-block">
                        <input type="text" th:value="${article.id}" name="id" id="id"
                               autocomplete="off" placeholder="请输入id" class="layui-input">
                    </div>
                </div>

                <div class="layui-form-item">
                    <label class="layui-form-label">标题</label>
                    <div class="layui-input-block">
                        <input type="text" id="title" name="title" th:value="${article.title}"  autocomplete="off" placeholder="请输入标题"
                               class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">主图</label>
                    <div class="layui-input-block">
                        <input type="text" id="img" name="img" th:value="${article.img}"  autocomplete="off" placeholder="请输入主图"
                               class="layui-input">
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">所属分类</label>
                        <div class="layui-input-block">
                            <select name="typeId" id="typeId">
                                <option value="" th:each="type,typeStat:${list}" th:value="${type.id}" th:text="${type.className}"></option>
                            </select>

                        </div>
                    </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">简介</label>
                    <div class="layui-input-block">
                        <input type="text" id="introduce" name="introduce" th:value="${article.introduce}"  autocomplete="off" placeholder="请输入简介"
                               class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">是否原创</label>
                    <div class="layui-input-block">
                        <input type="text" id="original" name="original" th:value="${article.original}"  autocomplete="off" placeholder="请输入是否原创"
                               class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">内容</label>
                    <div class="layui-input-block">
                        <input type="text" id="content" name="content" th:value="${article.content}"  autocomplete="off" placeholder="请输入内容"
                               class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">是否热门:1热门，0不热门</label>
                    <div class="layui-input-block">
                        <input type="text" id="isHot" name="isHot" th:value="${article.isHot}"  autocomplete="off" placeholder="请输入是否热门:1热门，0不热门"
                               class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">标签</label>
                    <div class="layui-input-block">
                        <input type="text" id="labels" name="labels" th:value="${article.labels}"  autocomplete="off" placeholder="请输入标签"
                               class="layui-input">
                    </div>
                </div>
            </div>
        </div>
    </div>
    <div class="bottom">
        <div class="button-container">
            <button type="submit" class="layui-btn layui-btn-normal layui-btn-sm" lay-submit="" lay-filter="article-update">
                <i class="layui-icon layui-icon-ok"></i>
                提交
            </button>
            <button type="reset" class="layui-btn layui-btn-primary layui-btn-sm">
                <i class="layui-icon layui-icon-refresh"></i>
                重置
            </button>
        </div>
    </div>
</form>
<th:block th:include="include :: footer"/>
<script>
    layui.use(['form', 'jquery','laydate'], function () {
        let form = layui.form;
        let $ = layui.jquery;
        var laydate = layui.laydate;
        // 日期选择
        laydate.render({
            elem: '#birthday' //指定元素
        });

        form.on('submit(article-update)', function (data) {
            $.ajax({
                url: '/blog/article/update',
                data: JSON.stringify(data.field),
                dataType: 'json',
                contentType: 'application/json',
                type: 'put',
                success: function (result) {
                    if (result.success) {
                        layer.msg(result.msg, {icon: 1, time: 1000}, function () {
                            parent.layer.close(parent.layer.getFrameIndex(window.name));//关闭当前页
                            parent.layui.table.reload("article-table");
                        });
                    } else {
                        layer.msg(result.msg, {icon: 2, time: 1000});
                    }
                }
            })
            return false;
        });
    })
</script>

</body>
</html>